package banmuoi.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;

import org.hibernate.Query;
import org.hibernate.Session;

import banmuoi.entity.Order;
import banmuoi.util.HibernateUtil;

@WebServlet("/crudOrder.do")
public class OrderAdmin extends HttpServlet{
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		Session session = HibernateUtil.openSession();
		
		//HIỆN DANH SÁCH
		String hql = "FROM Order ORDER BY id DESC";
		Query query = session.createQuery(hql);
		List<Order> entities = query.list();
		req.setAttribute("showOrders", entities);
			
		req.getRequestDispatcher("admin/OrderAdmin.jsp").forward(req, resp);
						
		session.close();
	}

}
